<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //要对arr数组每个元素*2
        let arr = [1, 2, 3, 4, 5, 6];
        //传统方式
        let newarr = [];
        for (let i = 0; i < arr.length; i++) {
            newarr.push(arr[i] * 2);
        }
        console.log(newarr);

        // map -- 自带的循环，并且会把处理的值回填对应的位置。
        var newarr2 = arr.map(ele => ele * 2);
        console.log(newarr2);

        //map处理对象的数据
        var users = [{ age: 10, name: "小张" }, { age: 14, name: "小刘" }, { age: 20, name: "小赵" }];
        var newUsers = users.map(function (ele) {
            ele.age = ele.age + 1;
            //你还可以给对象添加属性。
            ele.phone=123;
            return ele;
        });
        console.log(newUsers);
    </script>
</body>

</html>